/*
*编写程序使用replace_copy将一个容器中的序列复制给另一个容器，并将前一个序列中的值替换为指定的新值
*分别使用insert,back_inserter,front_inserter实现这个程序
*/
#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;

list<int> rcInserter(vector<int>,list<int>,int,int);
list<int> rcBackInserter(vector<int>,list<int>,int,int);
list<int> rcFrontInserter(vector<int>,list<int>,int,int);
int main()
{
	vector<int> ivec;
	ivec.push_back(100);
	ivec.push_back(200);
	ivec.push_back(100);
	ivec.push_back(200);
	ivec.push_back(100);

	list<int> ilist;
	ilist.push_back(1);
	ilist.push_back(2);
	ilist.push_back(3);
	ilist.push_back(4);
	ilist.push_back(5);

	//inserter
	list<int> lst1 = rcInserter(ivec,ilist,100,0);

	//back_inserter
	//list<int> lst = rcBackInserter(ivec,ilist,100,1000);

	//front_inserter
	//list<int> lst = rcFrontInserter(ivec,ilist,100,0);

	list<int>::iterator iter = lst.begin();
	while(iter != lst.end())
	{
		cout << *iter << "  ";
		++iter;
	}
	cout << endl;
	system("pause");
	return 0;
}

//使用inserter实现
list<int> rcInserter(vector<int> vec,list<int> lst,int beVal,int enVal)
{
	list<int>::iterator it = find(lst.begin(),lst.end(),3);
	replace_copy(vec.begin(),vec.end(),inserter(lst,it),beVal,enVal);
	return lst;
}

//使用back_inserter实现
list<int> rcBackInserter(vector<int> vec,list<int> lst,int beVal,int enVal)
{
	replace_copy(vec.begin(),vec.end(),back_inserter(lst),beVal,enVal);
	return lst;
}

//使用front_inserter实现
list<int> rcFrontInserter(vector<int> vec,list<int> lst,int beVal,int enVal)
{
	replace_copy(vec.begin(),vec.end(),front_inserter(lst),beVal,enVal);
	return lst;
}